layui.config({
    base: "js/"
}).use(['jquery', 'http', 'layer', 'config'], function () {
    var $ = layui.jquery,
        $layer = layui.layer,
        $cfg = layui.config(),
        $http = layui.http();

    function login() {
        var yzm = $("#yzm").val(),
            userName = $("#userName").val(),
            password = $("#password").val();
        if (!yzm || !userName || !password) {
            $layer.msg("请输入用户名和密码！");
            return;
        }
        if (yzm.toUpperCase() != codes.toUpperCase()) {
            layer.msg("验证码输入错误!请重新输入", {time: 1000}); //则弹出验证码输入错误
            change();//刷新验证码
            $("#yzm").val("");//清空文本框
            return;
        }
        var url = "admin/login.json";
        $.ajax({
            url: url,
            type: 'POST',
            data: {
                username: userName,
                password: password
            },
            dataType: 'json',
            success: function (data) {
                var status = data.status;
                if (status == 0) {
                    $layer.msg("登录成功");
                    window.location = "acp/index.html";
                } else {
                    $layer.msg(data.msg);
                }
            }
        });
    }

    $("#login").click(function () {
        login();
    });
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            login();
        }
    });
});